package com.ruoyi.project.game.topic.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.game.topic.domain.Topic;
import com.ruoyi.project.game.topic.service.ITopicService;
import com.ruoyi.project.game.topicgame.service.ITopicGameService;

/**
 * 游戏专题Controller
 * 
 * @author shixiangwen
 * @date 2020-02-11
 */
@Controller
@RequestMapping("/game/topic")
public class TopicController extends BaseController {
	private String prefix = "game/topic";

	@Autowired
	ITopicService topicService;

	@Autowired
	ITopicGameService topicGameService;

	@RequiresPermissions("game:topic:view")
	@GetMapping()
	public String topic() {
		return prefix + "/topic";
	}

	/**
	 * 查询游戏专题列表
	 */
	@RequiresPermissions("game:topic:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Topic topic) {
		startPage();
		List<Topic> list = topicService.selectTopicList(topic);
		return getDataTable(list);
	}

	/**
	 * 查询游戏专题游戏列表
	 */
	@RequiresPermissions("game:topic:list")
	@GetMapping("/detail/{topicId}")
	public String detail(@PathVariable("topicId") Long topicId, ModelMap mmap) {

		mmap.put("topic", topicService.selectTopicById(topicId));
		mmap.put("topicList", topicService.selectTopicList(new Topic()));
		return "game/topicgame/topicgame";
	}

	/**
	 * 导出游戏专题列表
	 */
	@RequiresPermissions("game:topic:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Topic topic) {
		List<Topic> list = topicService.selectTopicList(topic);
		ExcelUtil<Topic> util = new ExcelUtil<Topic>(Topic.class);
		return util.exportExcel(list, "topic");
	}

	/**
	 * 新增游戏专题
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存游戏专题
	 */
	@RequiresPermissions("game:topic:add")
	@Log(title = "游戏专题", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Topic topic) {
		return toAjax(topicService.insertTopic(topic));
	}

	/**
	 * 修改游戏专题
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		Topic topic = topicService.selectTopicById(id);
		mmap.put("topic", topic);
		return prefix + "/edit";
	}

	/**
	 * 修改保存游戏专题
	 */
	@RequiresPermissions("game:topic:edit")
	@Log(title = "游戏专题", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Topic topic) {
		return toAjax(topicService.updateTopic(topic));
	}

	/**
	 * 删除游戏专题
	 */
	@RequiresPermissions("game:topic:remove")
	@Log(title = "游戏专题", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(topicService.deleteTopicByIds(ids));
	}
}
